package com.itheima.web.service;
/*
 *FileName: LocationService
 *Created Date:2021/3/2 17:36
 *Developers: Mr.Seven
 */


import com.itheima.domain.mongo.UserLocationDTO;
import com.itheima.dubbo.api.UserLocationApi;
import com.itheima.web.domain.Address;
import com.itheima.web.domain.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * Mr.Seven的基操
 */
@Service
public class LocationService {

    @Reference
    private UserLocationApi userLocationApi;

    public ResponseEntity findLocation(Integer userId) {
        UserLocationDTO dto = userLocationApi.findLocation(userId);
        if (dto != null) {
            Address address = new Address();
            address.setAddressName(dto.getAddress());
            address.setLongitudeUser(dto.getLongitude());
            address.setLatitudeUser(dto.getLatitude());
            return ResponseEntity.ok(new Result(true, "查询成功", address));
        }
        return ResponseEntity.ok(new Result(false, "查询失败"));
    }
}
